use std::fs;

// 此代码来自于极客时间陈天陈老师的示例代码，学习使用
pub(crate) fn test_wechat() -> String {
    let url = "https://www.rust-lang.org";
    let output = "rust.md";
    println!("fetching url: {}", url);

    let body = reqwest::blocking::get(url).unwrap().text().unwrap();

    println!("Coverting html to markdown...");
    let md = html2md::parse_html(&body);
    fs::write(output, md.as_bytes()).unwrap();

    println!("Converted markdown has been saved in {}.", output);


    // 聊天室代码
    let alice = User { id: UserId(1), name: "Alice".into(), gender: Gender::Female };
    let bob = User { id: UserId(2), name: "Bob".into(), gender: Gender::Male };

    let topic = Topic { id: TopicId(1), name: "Rust".into(), owner: UserId(1) };
    let event1 = Event::Join(alice.id, topic.id);
    let event2 = Event::Join(bob.id, topic.id);
    let event3 = Event::Message(alice.id, topic.id, "Hello World".into());
    println!("event1: {:?}, event2: {:?}, event3: {:?}", event1, event2, event3);

    String::from("hello world")
}

#[derive(Debug)]
enum Gender {
    Unspecified = 1,
    Female = 2,
    Male = 3,
}

#[derive(Debug, Clone, Copy)]
struct UserId(u64);

#[derive(Debug, Clone, Copy)]
struct TopicId(u64);

#[derive(Debug)]
struct User {
    id: UserId,
    name: String,
    gender: Gender,
}

#[derive(Debug)]
struct Topic {
    id: TopicId,
    name: String,
    owner: UserId,
}

// 定义聊天室中可能发生的事件
#[derive(Debug)]
enum Event {
    Join(UserId, TopicId),
    Leave(UserId, TopicId),
    Message(UserId, TopicId, String),
}